package com.defines.ming.demo.controller;

import com.defines.ming.demo.model.ExpenseHeader;
import com.defines.ming.demo.model.ExpenseLine;
import com.defines.ming.demo.model.Result;
import com.defines.ming.demo.model.User;
import com.defines.ming.demo.service.ExpenseService;
import com.defines.ming.demo.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/expense")
public class ExpenseController {
    @Autowired
    private ExpenseService expenseService;
    @PostMapping("/insertExpense")
    public Result insertExpense(@RequestBody ExpenseHeader expenseHeader){
        System.out.println(expenseHeader.toString());
        expenseService.insertExpenseHeader(expenseHeader);
        return  ResultUtil.success(null);
    }
    @PostMapping("/insertExpLine")
    public Result insertExpLine(@RequestBody ExpenseLine expenseLine){
        System.out.println(expenseLine.toString());
        expenseService.insertExpenseLine(expenseLine);
        return ResultUtil.success(null);
    }
    @PostMapping("/getMyPendingList")
     public Result getMyPendingList(@RequestParam String employeeCode){
        System.out.println("employee:"+employeeCode);
        List<ExpenseHeader> list= expenseService.getMyPendingList(employeeCode);
        return  ResultUtil.success(list);
    }
    @PostMapping("/commitExpense")
    public Result commitExpLine(@RequestBody Map<String,String> map){
        System.out.println("map"+map.toString());
        expenseService.commitExpense(map.get("expenseNum"),map.get("status"),map.get("approveNode"));
        return ResultUtil.success(null);
    }
    @PostMapping("/getExpense")
    public Result getExpenseInstance(@RequestParam String expenseNum){
        System.out.println("expenseNum"+expenseNum);
        List<ExpenseHeader> list=expenseService.getExpenseInstance(expenseNum);
        return ResultUtil.success(list);
    }
}
